package com.example.wlzz.repository.mapper.admin;

import com.example.wlzz.dto.admin.UserDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface UserMapper {
    @Select("select count(1) from user_")
    int user_number();
    @Select("SELECT u.user_id,u.phone,u.create_time," +
            " ui.nick_name,ui.real_name,ui.birth,ui.school_name," +
            " r.role_name" +
            " FROM user_ u,user_info ui,user_with_role ur,role r " +
            " where u.user_id = ui.user_id" +
            " and u.user_id = ur.userid" +
            " and ur.role_id = r.id" +
            " ORDER BY u.create_time DESC " +
            " LIMIT #{start} , #{end}")
    List<UserDTO> getUserInfo(@Param("start") int start, @Param("end") int end);
    @Select("SELECT u.user_id,u.phone,u.create_time," +
            " ui.nick_name,ui.real_name,ui.birth,ui.school_name," +
            " r.id,r.role_name" +
            " FROM user_ u " +
            " INNER JOIN user_info ui " +
            " on u.user_id = ui.user_id" +
            " INNER JOIN user_with_role ur " +
            " on u.user_id = ur.userid" +
            " INNER JOIN role r  " +
            " on ur.role_id = r.id" +
            " where ui.nick_name like #{input_user_info}" +
            " or u.phone like #{input_user_info}" +
            " or u.user_id like #{input_user_info}")
    List<UserDTO> searchUser(@Param("input_user_info") String  input_user_info);

    @Select("SELECT u.user_id,u.phone,u.create_time," +
            " ui.nick_name,ui.real_name,ui.birth,ui.school_name," +
            " r.id role_id,r.role_name" +
            " FROM user_ u " +
            " INNER JOIN user_info ui " +
            " on u.user_id = ui.user_id" +
            " INNER JOIN user_with_role ur " +
            " on u.user_id = ur.userid" +
            " INNER JOIN role r  " +
            " on ur.role_id = r.id" +
            " where r.id in (2,3)")
    List<UserDTO> searchManager();



}
